package cn.tedu.lianxi1;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

public class Text6 {
    public static void main(String[] args) throws Exception {
   /*     method();
        System.out.println("---------");
        method2();

    */
        A3 a=new A3();
        a.method();
        System.out.println("------");
        a.method2();
    }

    public static void method() throws Exception {
        Class a=Wuzi.class;
        Method[] d = a.getDeclaredMethods();
        for (Method m : d) {
            System.out.println(m.getName());
            Class<?>[] p = m.getParameterTypes();
            System.out.println(Arrays.toString(p));
        }
        Method g = a.getDeclaredMethod("game", String.class);
        g.setAccessible(true);
        Object o=a.newInstance();
        g.invoke(o,"tick");
        Method e = a.getDeclaredMethod("eat");
        e.invoke(o,null);

    }

    public static void method2() throws Exception {
        Class a=Wuzi.class;
        Field[] d = a.getDeclaredFields();
        for (Field f : d) {
            System.out.println(f.getName());
            System.out.println(f.getType().getName());
        }
        Field s = a.getDeclaredField("score");
        s.setAccessible(true);
        Object o=a.newInstance();
        s.set(o,99.6);
        System.out.println(s.get(o));

    }
}
class A3{
    public void method() throws Exception {
        Class a=Wuzi.class;
        Method[] d = a.getDeclaredMethods();
        for (Method m : d) {
            System.out.println(m.getName());
            Class<?>[] p = m.getParameterTypes();
            System.out.println(Arrays.toString(p));
        }
        Method n = a.getDeclaredMethod("eat");
        n.setAccessible(true);
        Object o=a.newInstance();
        n.invoke(o,null);
        Method s = a.getDeclaredMethod("sleep", int.class, String.class);
        s.invoke(o,20,"龙脉");

    }
    public void method2() throws Exception {
        Class a=Wuzi.class;
        Field[] d = a.getDeclaredFields();
        for (Field f : d) {
            System.out.println(f.getName());
            System.out.println(f.getType().getName());
        }
        Field s = a.getDeclaredField("name");
        s.setAccessible(true);
        Object o=a.newInstance();
        s.set(o,"maeng");
        System.out.println(s.get(o));

    }
}